/**
 * Created by henian.xu on 2017/3/30.
 *
 */
$(function() {

  $('#jquery_jplayer_1').jPlayer({
    ready: function() {
      $(this).jPlayer('setMedia', {
        title: 'Big Buck Bunny',
        m3u8v: 'http://media.qztvxwgj.com/fbcee34b5eb24eb7a85d422334dd98cd/0624lb01rencai/0624lb01rencai.m3u8',
        // m4v: 'http://cloud.video.taobao.com/play/u/2554695624/p/1/e/6/t/1/fv/102/28552077.mp4',
        // ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
        // webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
        poster: '../static/images/playing/player.jpg',
      });
    },
    swfPath: '../static/libs/jplayer/jquery.jplayer.swf',
    solution: 'flash, html',
    supplied: 'webmv, ogv, m4v, m3u8v',
    size: {
      width: '680px',
      height: '460px',
      cssClass: 'jp-video-460p',
    },
    useStateClassSkin: true,
    autoBlur: false,
    smoothPlayBar: true,
    keyEnabled: true,
    remainingDuration: true,
    toggleDuration: true,
  });

  $('.z-tabs').tabs({
    tabsChange: function($tab, $panel, index) {
      if (!$panel.length) return;
      var
          offset = $panel.scrollTop(),
          $active = $panel.find('li.active');
      if (!$active.length) return;
      $panel.scrollTop($active.position().top + offset - 34 - 17);
      console.log($active.position(), offset);
    },
  });

  //保证节目显示
  (function() {
    var $panel = $('.z-tabs-pane.z-active');
    if (!$panel.length) return;
    var
        offset = $panel.scrollTop(),
        $active = $panel.find('li.active');
    if (!$active.length) return;
    $panel.scrollTop($active.position().top + offset - 34 - 17);
  })();

  var commentUm = UE.getEditor('commentUm', {
    autoFloatEnabled: false,
    //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
    toolbars: [['emotion']],
    //focus时自动清空初始化时的内容
    autoClearinitialContent: true,
    //关闭字数统计
    wordCount: false,
    //关闭elementPath
    elementPathEnabled: false,
    initialFrameWidth: '100%',
    //默认的编辑区域高度
    initialFrameHeight: 80,
    //更多其他参数，请参考umeditor.config.js中的配置项
  });
  var replyUE = {};

  function creatUE(id) {
    replyUE[id] = UE.getEditor(id, {
      autoFloatEnabled: false,
      //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
      toolbars: [['']],
      //focus时自动清空初始化时的内容
      autoClearinitialContent: true,
      //关闭字数统计
      wordCount: false,
      //关闭elementPath
      elementPathEnabled: false,
      initialFrameWidth: '100%',
      //默认的编辑区域高度
      initialFrameHeight: 80,
      //更多其他参数，请参考umeditor.config.js中的配置项
    });
  }

  //jQ 缓存
  var
      $comment = $('.comment'),
      $commentList = $('.comment-list');

  //查看回复点击事件
  $commentList.on('click', '.look-reply-btn', function(e) {
    var
        $this = $(this),
        $desc = $this.closest('.desc'),
        $replyBox = $desc.children('.reply-box');
    if ($replyBox.is(':visible')) {
      $replyBox.hide();
    } else {
      $replyBox.show();
    }
  });

  //回复点击事件
  $commentList.on('click', '.reply-btn', function(e) {
    var
        $this = $(this),
        $desc = $this.closest('.desc'),
        $replyEdit = $desc.children('.reply-edit'),
        $replyEditor = $replyEdit.children('.replyEditor'),
        id = $replyEditor.attr('id');

    if (!id) {
      id = 'replyEditor' + new Date().getTime();
      $replyEditor.attr('id', id);
      creatUE(id);
    }

    if ($replyEdit.is(':visible')) {
      $replyEdit.hide();
    } else {
      $replyEdit.show();
    }
  });

  //评论发送
  $comment.on('click', '.send-btn', function(e) {
//在这里写 ajax 提交;
    console.log(commentUm.getContent());
  });

  //回复列表发送
  $commentList.on('click', '.send-btn', function(e) {
    var
        $this = $(this),
        $replyEditor = $this.siblings('.replyEditor'),
        id = $replyEditor.attr('id');

    //在这里写 ajax 提交;
    console.log(replyUE[id].getContent());

  });

});








